
<template>
  <base-breadcrumb :title="titleName">
    <a-row
      :gutter="10"
      class="page-height"
    >
      <!-- 树搜索 -->
      <a-col
        :span="6"
        class="permission-collapsed"
        :class="{ 'permission-tree-collapsed': collapsed }"
      >
        <a-card
          :style="{ border: collapsed ? 'none' : 'border: 1px solid #e8e8e8' }"
          class="page-height-tree"
        >
          <title-name title="组织架构" />
          <PermissionTreeOrganization
            :collapsed.sync="collapsed"
            @select="handleSelect"
          />
        </a-card>
      </a-col>
      <!-- 树搜索 -->
      <a-col
        :span="18"
        class="permission-collapsed page-height-list-wrapper"
        :style="collapsed ? 'width:calc(100% - 10px)' : ''"
      >
        <searchData
          :search-data="searchArr"
          @search="search"
        />
        <a-card
          :bordered="false"
          class="page-height-list"
        >
          <div class="table-operator">
            <a-button
              v-btnPermission="[{code:'seex_pm_001_add_01',ident:'prma_seex'},{code:'buco_pm_001_add_01',ident:'prma_buco'}]"
              type="primary"
              icon="plus"
              @click="handleAdd"
            >
              新增项目
            </a-button>
            <!--<a-button @click="exportAll" >导出</a-button>-->

            <!--<export-excel :tableData="tableData"></export-excel>-->
            <!--<excel ref="exportAll" fileName="项目列表" is-click-generate="false">-->
            <a-button
              slot="excelBtn"
              v-btnPermission="[{code:'seex_pm_001_exp_12',ident:'prma_seex'},{code:'buco_pm_001_exp_12',ident:'prma_buco'}]"
              @click="handleExportMarketingList"
            >
              导出
            </a-button>
            <!--</excel>-->
          </div>
          <div class="pub-table-select-count">
            <a-icon
              type="info-circle"
              theme="twoTone"
            />
            <span style="margin-right: 12px">
              <!--已选择：<span class="totalSize">{{selectedNum}} </span> 项 |-->
              项目总共：<span class="totalSize">{{ totalSize }} </span> 项
            </span>
          </div>
          <list-table
            ref="table"
            :row-key="(record) => record.projectId"
            :columns="columns"
            :request="loadData"
          >
            <span
              slot="serial"
              slot-scope="text, record, index"
            >{{ index + 1 }}</span>
            <template
              slot="statusCode"
              slot-scope="text"
            >
              <a-badge
                :status="text | statusTypeFilter"
                :text="text | statusFilter"
              />
            </template>
            <span
              slot="projectNum"
              slot-scope="text, record"
            >
              <span
                v-if="record.projectNum == '' || record.projectNum == null"
                style="color: #dcdcdc; font-size: 14px"
              >
                待定</span>
              <span v-else> {{ record.projectNum }}</span>
            </span>
            <span
              slot="projectTime"
              slot-scope="text, record"
            >
              <template> {{ record.contractStartDate }}—{{ record.contractFinishDate }} </template>
            </span>
            <span
              slot="projectFormat"
              slot-scope="text, record"
            >
              <template>
                {{ record.projectFormat && record.projectFormat.join('&') }}
              </template>
            </span>
            <template
              slot="action"
              slot-scope="text, record"
            >
              <MoreButton>
                <template>
                  <a
                    v-btnPermission="[{code:'seex_pm_001_loo_02',ident:'prma_seex'},{code:'buco_pm_001_loo_02',ident:'prma_buco'}]"
                    @click="handleSub(record)"
                  >查看</a>
                </template>
                <template v-if="
                    record.statusCode == '0' ||
                    record.statusCode == '2' ||
                    (record.statusCode == '3' && record.innerPackageCode != 1)
                  ">
                  <a
                    v-btnPermission="[{code:'seex_pm_001_edi_03',ident:'prma_seex'},{code:'buco_pm_001_edi_03',ident:'prma_buco'}]"
                    @click="handleEdit(record)"
                  >编辑</a>
                </template>
                <template v-if="record.statusCode == '0'">
                  <a
                    v-btnPermission="[{code:'seex_pm_001_del_11',ident:'prma_seex'},{code:'buco_pm_001_del_11',ident:'prma_buco'}]"
                    @click="handleDel(record)"
                  >删除</a>
                </template>
                <template v-if="
                    (record.statusCode == '3' && record.innerPackageCode != 1) ||
                    (record.statusCode && record.statusCode != '0' && record.statusCode != '3')
                  ">
                  <a
                    v-btnPermission="[{code:'seex_pm_001_moi_10',ident:'prma_seex'},{code:'buco_pm_001_moi_10',ident:'prma_buco'}]"
                    @click="handleApproveDetail(record)"
                  >审批信息</a>
                </template>
                <!--<span v-if="record.statusCode == '0' || record.statusCode == '3' "><a-divider v-btnPermission="'pm_001_sub_06'" type="vertical"/><a @click="handleApprove(record)" v-btnPermission="'pm_001_sub_06'">提交审批</a></span>-->
                <template v-if="
                    record.statusCode != '0' &&
                    record.statusCode != '1' &&
                    record.statusCode != '3' &&
                    record.designTypeId == null &&
                    record.innerPackageCode != 1
                  ">
                  <a
                    v-btnPermission="[{code:'seex_pm_001_des_07',ident:'prma_seex'},{code:'buco_pm_001_des_07',ident:'prma_buco'}]"
                    @click="handleDesign(record)"
                  >设置设计类型</a>
                </template>
                <template v-if="
                    record.statusCode != '0' &&
                    record.statusCode != '1' &&
                    record.statusCode != '3' &&
                    record.techManageTypeId == null &&
                    record.innerPackageCode != 1
                  ">
                  <a
                    v-btnPermission="[{code:'seex_pm_001_scl_08',ident:'prma_seex'},{code:'buco_pm_001_scl_082',ident:'prma_buco'}]"
                    @click="handleTechnogy(record)"
                  >设置科技类型</a>
                </template>
                <template v-if="
                    record.statusCode != '0' &&
                    record.statusCode != '1' &&
                    record.statusCode != '3' &&
                    record.constructionTypeId == null &&
                    record.innerPackageCode != 1 &&
                    record.qualityTypeButton
                  ">
                  <a
                    v-btnPermission="[{code:'seex_pm_001_qua_09',ident:'prma_seex'},{code:'buco_pm_001_qua_09',ident:'prma_buco'}]"
                    @click="handleQuality(record)"
                  >设置质量类型</a>
                </template>
                <template v-if="
                    record.statusCode > '4'
                  ">
                  <a
                    v-btnPermission="[{code:'seex_pm_001_fin_16',ident:'prma_seex'},{code:'buco_pm_001_fin_16',ident:'prma_buco'}]"
                    @click="handleCompleted(record)"
                  >竣工设置</a>
                </template>
                <template v-if="record.statusCode == '4' && record.innerPackageCode != 1">
                  <a
                    v-btnPermission="[{code:'seex_pm_001_sta_04',ident:'prma_seex'},{code:'buco_pm_001_sta_04',ident:'prma_buco'}]"
                    @click="handleSetup(record)"
                  >开工设置</a>
                </template>
                <template v-if="
                    record.signingContract == '否' &&
                    record.statusCode != '0' &&
                    record.statusCode != '1' &&
                    record.statusCode != '3' &&
                    record.innerPackageCode != 1
                  ">
                  <a
                    v-btnPermission="[{code:'seex_pm_001_con_05',ident:'prma_seex'},{code:'buco_pm_001_con_05',ident:'prma_buco'}]"
                    @click="handleContractEdit(record)"
                  >合同信息编辑</a>
                </template>
                <span
                  v-if="parseInt(record.statusCode) === 2 || parseInt(record.statusCode) > 3"
                  v-btnPermission="[{code:'seex_pm_001_zyc_13',ident:'prma_seex'},{code:'buco_pm_001_zyc_13',ident:'prma_buco'}]"
                >
                  <a @click="handleCmportance(record)">变更重要程度</a>
                </span>
                <span
                  v-if="parseInt(record.statusCode) === 2 || parseInt(record.statusCode) > 3"
                  v-btnPermission="[{code:'seex_pm_001_jzl_14',ident:'prma_seex'},{code:'buco_pm_001_jzl_14',ident:'prma_buco'}]"
                >
                  <a @click="handleCode(record)">局质量系统项目编码</a>
                </span>
                <span
                  v-if="parseInt(record.statusCode) === 2 || parseInt(record.statusCode) > 3"
                  v-btnPermission="[{code:'seex_pm_001_yun_15',ident:'prma_seex'},{code:'buco_pm_001_yun_15',ident:'prma_buco'}]"
                >
                <a @click="handleYzCode(record)">云筑项目编码</a>
                </span>
              </MoreButton>
            </template>
          </list-table>
          <!-- 竣工设置 -->
          <beCompleted
            ref="createModal"
            :visible="visibleCompleted"
            :loading="confirmLoading"
            :row="mdl"
            @cancel="cancelBeCompleted()"
          />
          <ApprovalDetails
            :title="'审批详情'"
            :business-id="businessId"
            :projectCompletionId="projectCompletionId"
            :visible="visibleApprove"
            @cancel="visibleApprove = false"
            @confirm="visibleApprove = false"
          />
          <!--          &lt;!&ndash; 变更重要程度 &ndash;&gt;-->
          <ChangeCmportanceOrCode
            :visible.sync="cmportanceVisible"
            :type="cmportanceType"
            :data="cmportanceData"
            @update="list()"
          />
          <!-- 变更重要程度 -->
        </a-card>
      </a-col>
    </a-row>
  </base-breadcrumb>
</template>

<script>
import { STable, Ellipsis } from '@/components'
import { getProjectsList, projectsAudit, projectsStarts, getProjectFrom, deleteProjects, exportExcels, settingProjectCompletion, projectCompletionDetail } from '@/api/project/projects'
import { getImportantsList } from '@/api/project/importants'
import ApprovalDetails from './approvalDetails'
import PermissionTreeOrganization from '@/components/businessComponents/PermissionTreeOrganization'

import ChangeCmportanceOrCode from './components/ChangeCmportanceOrCode'
import MoreButton from '@/components/MoreButton'
import beCompleted from './beCompleted'
const columns = [
  {
    title: '序号',
    width: 65,
    scopedSlots: { customRender: 'serial' }
  },
  {
    title: '项目编号',
    dataIndex: 'projectNum',
    width: 120,
    scopedSlots: { customRender: 'projectNum' }
  },
  {
    title: '项目备案名称',
    width: 200,
    dataIndex: 'projectName',
    ellipsis: true
    // scopedSlots: { customRender: 'projectName' }
  },
  {
    title: '项目简称',
    width: 200,
    dataIndex: 'shortName',
    ellipsis: true
  },
  {
    title: '项目业态',
    dataIndex: 'projectFormat',
    width: 100
    // scopedSlots: { customRender: 'projectFormat' }
  },
  {
    title: '分公司',
    width: 120,
    dataIndex: 'branchName'
  },
  {
    title: '项目地点',
    dataIndex: 'projectAddress'
  },
  {
    title: '项目重要程度',
    dataIndex: 'projectImportanceName'
  },
  {
    title: '公司级大客户',
    width: 200,
    dataIndex: 'majorCustomerName'
  },
  {
    title: '备案项目经理',
    width: 120,
    dataIndex: 'projectManagerName'
  },
  {
    title: '合同工期(天)',
    width: 80,
    dataIndex: 'projectContractCycle'
  },
  {
    title: '合同开竣工时间',
    dataIndex: 'projectTime',
    width: 140,
    scopedSlots: { customRender: 'projectTime' }
  },
  {
    title: '立项日期',
    dataIndex: 'projectCreateTime',
    width: 120
  },
  {
    title: '状态',
    dataIndex: 'statusCode',
    width: 140,
    scopedSlots: { customRender: 'statusCode' }
  },
  {
    title: '操作',
    dataIndex: 'action',
    width: 200,
    fixed: 'right',
    scopedSlots: { customRender: 'action' }
  }
]

const statusMap = {
  0: { text: '待提交审批', status: 'warning' },
  1: { text: '审批中', status: 'processing' },
  2: { text: '待立项', status: 'success' },
  3: { text: '审批不通过', status: 'error' },
  4: { text: '施工准备阶段', status: 'success' },
  5: { text: '在建', status: 'success' },
  6: { text: '停工', status: 'default' },
  7: { text: '停缓建', status: 'default' },
  8: { text: '维保期', status: 'default' },
  9: { text: '维保期截止', status: 'default' }
}
export default {
  name: 'a' + Date.now(),
  props: {
    editType: {
      type: String
    }
  },
  components: {
    Ellipsis,
    ApprovalDetails,
    PermissionTreeOrganization,
    ChangeCmportanceOrCode,
    MoreButton,
    beCompleted
  },
  data() {
    this.columns = columns
    return {
      datas: [],
      tableData: [
        { id: '1', name: '张三6' },
        { id: '2', name: '李四6' },
        { id: '3', name: '王五6' }
      ], // 导出数据

      pageNo: 1,
      pageSize: 10,
      totalSize: 0,
      projectCompletionId: '',
      visibleApprove: false,

      spinning: false,

      expand: true,

      onlyCompany: 1,
      searchArr: [
        // 搜索框
        {
          name: '项目备案名称',
          value: 'projectName',
          type: 'input'
        },
        {
          name: '项目业态',
          value: 'projectFormat',
          type: 'select',
          data: []
        },
        {
          name: '项目重要程度',
          value: 'projectImportanceName',
          type: 'select',
          data: [],
        },
        {
          name: '状态',
          value: 'projectStatusQuery',
          type: 'selectMode',
          data: [
          {
              value: 'DRAFT',
              label: '待提交'
            },
            {
              value: 'SUBMITTED',
              label: '审批中'
            },
            {
              value: 'REJECTED',
              label: '审批不通过'
            },
            {
              value: 'ONGOING',
              label: '施工准备阶段'
            },
            {
              value: 'START_WORKING',
              label: '在建'
            },
            {
              value: 'SHUTDOWN',
              label: '停工'
            },
            {
              value: 'SUSPENDED',
              label: '停缓建'
            },
            {
              value: 'MAINTENANCE_PERIOD',
              label: '维保期'
            },
            {
              value: 'COMPLETE',
              label: '维保期截止'
            },
          ]
        }
        // {
        //   name: '分公司',
        //   valueKey: 'branchCode',
        //   type: SelectSubCompany
        // }
      ],
      titleName: '',
      loading: false,
      visible: false,
      visibleCompleted: false,
      confirmLoading: false,
      mdl: null,
      // 高级搜索 展开/关闭
      advanced: false,
      // 查询参数
      queryParam: {},
      // 加载数据方法 必须为 Promise 对象
      selectedRowKeys: [],
      selectedRows: [],
      selectedNum: 0,

      totalDels: {},
      id: [],

      cash: [
        {
          // 导出数据
        }
      ],
      //组织架构选中项
      select: {},
      // 变更重要程度或者项目编码模态框显示隐藏
      cmportanceVisible: false,
      // 变更重要程度或者项目编码模态框类型
      cmportanceType: 0,
      // 变更重要程度或者项目编码模态框数据
      cmportanceData: {},
      // 收缩展开树
      collapsed: false,

      loadData: async (p) => {
        let branchCode = undefined
        if (this.select.tageCode === 'BC') {
          branchCode = this.select.orgId
        }
        let projectId = this.select.projectId || undefined
        //businessType 业务类型（1：项目列表，2：专业项目列表）
        let searchData = Object.assign(p, this.queryParam, { branchCode, projectId, statusSet:[0,1,2,3,4,5,6], auditStatusSet:[0,1,2,3], businessType:1})
        return getProjectsList(searchData).then((res) => {
          this.totalSize = res.totalSize
          return res
        })
      },
      businessId: null
    }
  },
  filters: {
    statusFilter(type) {
      return statusMap[type].text
    },
    statusTypeFilter(type) {
      return statusMap[type].status
    }
  },
  mounted: function () {
    // this.$refs.exportAll.tableToExcelFile(this.$refs.table)
  },
  async created() {
    this.getProjectFrom()
    this.getImportantsList();
  },
  computed: {
    rowSelection() {
      return {
        type: 'radio',
        selectedRowKeys: this.selectedRowKeys,
        selectedRows: this.selectedRows, // 当前行所有数据
        onChange: this.onSelectChange
      }
    }
  },
  methods: {
    // 导出复杂表头
    handleExportMarketingList() {
      exportExcels(this.queryParam).then((res) => {
        if (res.code == 200 || res.data.code == 200) {
          this.cash = res.data

          require.ensure([], () => {
            const { export_json_to_excel } = require('@/components/exportExcel/Export2Excel2')
            //multiHeader数组里面添加的是一级表头的名称，要按顺序添加每个表头的的名称，如果遇到横向合并单元格的地方，合并了多少个单元格，就要留几个空字符串占位
            const multiHeader = [
              [
                '序号',
                '项目编号',
                '项目备案名称',
                '项目简称',
                '所属地域与辖区',
                '',
                '',
                '',
                '',
                '',
                '',
                '',
                '',
                '项目属性',
                '',
                '',
                '',
                '',
                '',
                '',
                '',
                '',
                '',
                '',
                '相关方属性',
                '',
                '',
                '',
                '',
                '',
                '',
                '',
                '',
                '项目概况',
                '',
                '',
                '',
                '',
                '',
                '',
                '',
                '',
                '',
                '',
                '',
                '合同额情况（含补充合同、变更合同）',
                '',
                '合同工期与实际工期情况',
                '',
                '',
                '备案/实际项目经理'
              ]
            ]

            //tHeader数组里面放的是二级表头的名称，也要按顺序添加每个表头的的名称，添加的时候要注意，如果是一级表头上下单元格合并地方，要用空字符串补上占位。
            const tHeader = [
              '',
              '',
              '',
              '',
              '区域一级管辖单位（所属分局）',
              '区域二级管辖单位（所属办事处）',
              '承接名义',
              '实施单位（所属二级单位）',
              '实施单位（所属三级单位）',
              '项目一级地域',
              '项目二级地域',
              '项目三级地域',
              '项目四级地域',
              '项目类型',
              '结构类型',
              '风险条件',
              '项目所属业态',
              '局级大客户',
              '公司级大客户',
              '项目状态',
              '项目设计管理类别',
              '项目科技管理类别',
              '项目质量管理类别',
              '是否内部分包',
              '设计单位名称',
              '工程承包模式',
              '建设单位名称',
              '建设单位性质',
              '建设单位社会统一代码',
              '勘察单位名称',
              '咨询单位名称',
              '监理单位名称',
              '审计单位名称',
              '合同总建筑面积（地上）万㎡',
              '合同总建筑面积（地下）万㎡',
              '合同总建筑面积万㎡',
              '合同工程里程Km',
              '合同单体工程个数',
              '最高(长）单位工程米数（公里数）',
              '项目特点或难点',
              '主施工范围',
              '计划创优级别',
              '计划创优内容',
              '计划观摩级别',
              '计划观摩内容',
              '原合同额万元',
              '自有施工合同额万元',
              '原合同开工日期',
              '原合同竣工日期',
              '原合同工期',
              '实际项目经理姓名'
            ]

            //filterVal数组里面放的是表头title对应的字段名称
            const filterVal = [
              'sortNumber',
              'projectNum',
              'projectName',
              'shortName',
              'jurisdictionOneName',
              'jurisdictionTwoName',
              'undertakeName',
              'implementationTwoName',
              'implementationThreeName',
              'oneAreaName',
              'secondAreaName',
              'threeAreaName',
              'fourAreaName',
              'projectTypeName',
              'structureTypeName',
              'riskConditionName',
              'projectFormatName',
              'bureauCustomerName',
              'companyCustomerName',
              'statusName',
              'designTypeName',
              'technologyName',
              'qualityName',
              'innerPackageName',
              'designUnitName',
              'contractModelName',
              'constructionName',
              'constructionNatureName',
              'constructionCode',
              'surveyName',
              'consultingName',
              'supervisionName',
              'auditName',
              'contractAreaGround',
              'contractAreaUnderground',
              'contractTotalArea',
              'contractMileage',
              'contractSingleProject',
              'engineeringMeters',
              'projectFeatures',
              'mainScope',
              'excellencePlanName',
              'excellentContent',
              'observePlanName',
              'observeContent',
              'contractValue',
              'ownerContractValue',
              'contractStartDate',
              'contractEndDate',
              'contractDays',
              'realityPmName'
            ]

            // this.cash是后端返回来的数组，用map方法遍历，这里你可以改你想要的数据，最后用return将每个字段一次返回就好啦
            const list = this.cash.map((item, key) => {
              return {
                sortNumber: item.sortNumber || null,
                projectNum: item.projectNum || null,
                projectName: item.projectName || null,
                shortName: item.shortName || null,
                
                jurisdictionOneName: item.jurisdictionOneName || null,
                jurisdictionTwoName: item.jurisdictionTwoName || null,
                undertakeName: item.undertakeName || null,
                implementationTwoName: item.implementationTwoName || null,
                implementationThreeName: item.implementationThreeName || null,
                oneAreaName: item.oneAreaName || null,
                secondAreaName: item.secondAreaName || null,
                threeAreaName: item.threeAreaName || null,
                fourAreaName: item.fourAreaName || null,

                projectTypeName: item.projectTypeName || null,
                structureTypeName: item.structureTypeName || null,
                riskConditionName: item.riskConditionName || null,
                projectFormatName: item.projectFormatName || null,
                bureauCustomerName: item.bureauCustomerName || null,
                companyCustomerName: item.companyCustomerName || null,
                statusName: item.statusName || null,
                designTypeName: item.designTypeName || null,
                technologyName: item.technologyName || null,
                qualityName: item.qualityName || null,
                innerPackageName: item.innerPackageName || null,

                designUnitName: item.designUnitName || null,
                contractModelName: item.contractModelName || null,
                constructionName: item.constructionName || null,
                constructionNatureName: item.constructionNatureName || null,
                constructionCode: item.constructionCode || null,
                surveyName: item.surveyName || null,
                consultingName: item.consultingName || null,
                supervisionName: item.supervisionName || null,
                auditName: item.auditName || null,

                contractAreaGround: item.contractAreaGround || null,
                contractAreaUnderground: item.contractAreaUnderground || null,
                contractTotalArea: item.contractTotalArea || null,
                contractMileage: item.contractMileage || null,
                contractSingleProject: item.contractSingleProject || null,
                engineeringMeters: item.engineeringMeters || null,
                projectFeatures: item.projectFeatures || null,
                mainScope: item.mainScope || null,
                excellencePlanName: item.excellencePlanName || null,
                excellentContent: item.excellentContent || null,
                observePlanName: item.observePlanName || null,
                observeContent: item.observeContent || null,

                contractValue: item.contractValue || null,
                ownerContractValue: item.ownerContractValue || null,

                contractStartDate: item.contractStartDate || null,
                contractEndDate: item.contractEndDate || null,
                contractDays: item.contractDays || null,

                realityPmName: item.realityPmName || null
              }
            })
            // merges是进行所有表头的单元格合并，数组里面的每个元素的填写规则是：按从左往右的顺序依次填写，
            // 字母是指excel里面的第几列，数字表示第几行，如果是上下的单元格合并，就是按从上往下填写，比
            // 如'A1:A2'代表的是A列的第一个单元格和A列的第二个单元格合并，如果是左右的单元格合并，也是从左往右填写，同理，
            const merges = ['A1:A2', 'B1:B2', 'C1:C2','D1:D2', 'E1:M1', 'N1:W1', 'X1:AF1', 'AG1:AR1', 'AS1:AT1', 'AU1:AW1', 'AX1:AX1    ']
            if (list) {
              const data = this.formatJson(filterVal, list) // 生成json数据
              export_json_to_excel({
                multiHeader, // 这里是第一行的表头
                header: tHeader, // 这里是第二行的表头
                data,
                filename: '在建项目信息表', //这里填的是导出excel的名称
                merges
              })
            } else {
              alert('暂无无数据')
            }
          })
        }
      })
    },
    formatJson(filterVal, jsonData) {
      return jsonData.map((v) => filterVal.map((j) => v[j]))
    },

    // 导出
    // exportAll: function() {
    //   axios({
    //     /*url: this.exportUrl,*/
    //     url: ` `,  // 导出路径
    //     method: "get",
    //     responseType: "blob"
    //   }).then(res => {
    //     console.log(res);
    //     var blob = new Blob([res.data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8' }); //application/vnd.openxmlformats-officedocument.spreadsheetml.sheet这里表示xlsx类型
    //
    //     if (window.navigator.msSaveBlob) {  //没有此判断的话，ie11下的导出没有效果
    //       window.navigator.msSaveBlob(blob, unescape(res.headers.filename.replace(/\\u/g, '%u')));
    //     } else {
    //       var downloadElement = document.createElement('a');
    //       var href = window.URL.createObjectURL(blob); //创建下载的链接
    //
    //       downloadElement.href = href;
    //       downloadElement.download =  unescape(res.headers.filename.replace(/\\u/g, '%u')); //下载后文件名
    //
    //       document.body.appendChild(downloadElement);
    //       downloadElement.click(); //点击下载
    //
    //       document.body.removeChild(downloadElement); //下载完成移除元素
    //
    //       window.URL.revokeObjectURL(href); //释放掉blob对象
    //     }
    //   })
    // },

    handlePageChange(pageNo, pageSize) {
      this.pageNo = pageNo
      this.list()
      this.selectedRowKeys = []
    },
    showSizeChange(pageNo, pageSize) {
      this.pageNo = 1
      this.pageSize = pageSize
      this.list()
    },

    list(params, callback) {
      this.$refs.table.refresh(true)
    },

    // 删除项目
    handleDel(record) {
      let that = this
      that.$confirm({
        title: '删除',
        content: '确定删除待提交审核的项目吗？',
        onOk() {
          deleteProjects({ id: record.projectId }).then((res) => {
            if (res.data == 200 || res.data.code == 200) {
              that.$message.success('删除成功！')
              that.list() // 更新列表
              that.selectedRows = []
              that.selectedRowKeys = []
            }
          })
        },
        onCancel() {}
      })
    },

    handleApproveDetail(record) {
      this.visibleApprove = true
      this.businessId = record.projectId
      this.projectCompletionId = record.projectCompletionId
    },
    getProjectFrom() {
      getProjectFrom().then((res) => {
        this.searchArr[1].data = this.getLabelData(res.data)
      })
    },

    handleApprove(val) {
      let that = this
      that.$confirm({
        title: '是否确定提交立项审批?',
        content: '',
        onOk() {
          return new Promise((resolve, reject) => {
            let data = { id: val.projectId }
            projectsAudit(data)
              .then((res) => {
                if (res.data.code == 200) {
                  that.$message.success('审批成功！')
                  that.list()
                } else {
                  that.$message.error('审批失败！')
                }
              })
              .catch((e) => {
                that.$message.error(e)
              })
              .finally(() => {
                resolve()
              })
          })
        },
        onCancel() {}
      })
    },

    handleSetup(val) {
      let that = this
      this.$confirm({
        title: '是否将项目状态更改为 "在建" 状态?',
        content: '',
        onOk() {
          projectsStarts({ id: val.projectId }).then((res) => {
            if (res.data.code == 200) {
              that.$message.success('在建状态设置成功！')
              that.list()
            }
          })
        },
        onCancel() {}
      })
    },

    search(values) {
      this.pageNo = 1
      this.queryParam = values
      this.list()
    },

    resetSearch() {
      this.queryParam = {}
    },

    deletes() {},
    handleAdd() {
      this.$router.push('/project/addProjects/add')
    },
    handleDesign(record) {
      this.$router.push({ path: '/design/update', query: { projectId: record.projectId, branchCode: '3' } })
    },
    handleTechnogy(record) {
      this.$router.push({ path: '/technogy/update', query: { projectId: record.projectId, branchCode: '2' } })
    },
    handleQuality(record) {
      this.$router.push({ path: '/quality/update', query: { projectId: record.projectId, branchCode: '4' } })
    },
    handleCompleted(record) {
      this.mdl = record;
      this.visibleCompleted = true;
    },
    handleEdit(record) {
      this.$router.push({ path: '/project/addProjects/edit', query: { projectId: record.projectId } })
    },
    handleSub(record) {
      this.$router.push({ path: '/project/details', query: { projectId: record.projectId, isDetails: 0 } })
    },
    handleContractEdit(record) {
      // 合同信息编辑
      // this.$router.push({ path: '/project/contractInfo', query: { projectId: record.projectId } })
      this.$router.push({
        path: '/project/addProjects/edit',
        query: { projectId: record.projectId, pageType: 'projectApproval' }
      })
    },
    onSelectChange(selectedRowKeys, selectedRows) {
      this.selectedNum = selectedRowKeys.length

      this.selectedRowKeys = selectedRowKeys
      this.selectedRows = selectedRows
    },
    toggleAdvanced() {
      this.advanced = !this.advanced
    },
    /**
     * @description: 树选中
     * @param {object} node 节点对象
     * @return {void}
     */
    handleSelect(node) {
      this.select = node
      this.list()
    },
    /**
     * @description: 变更重要程度
     * @param {object} record 行数据
     * @return {void}
     */
    handleCmportance(record) {
      this.cmportanceVisible = true
      this.cmportanceType = 0
      this.cmportanceData = record
    },
    /**
     * @description: 局质量系统项目编码
     * @param {object} record 行数据
     * @return {void}
     */
    handleCode(record) {
      this.cmportanceVisible = true
      this.cmportanceType = 1
      this.cmportanceData = record
    },
    /**
     * @description: 云筑项目编码
     * @param {object} record 行数据
     * @return {void}
     */
    handleYzCode(record) {
      this.cmportanceVisible = true
      this.cmportanceType = 2
      this.cmportanceData = record
    },
    getImportantsList() {
      getImportantsList().then((res) => {
        res.data.map((item)=> {
          item.label = item.importantName
          item.value = item.importantId
        })
        this.searchArr[2].data = res.data;
      })
    },
    cancelBeCompleted() {
      this.visibleCompleted = false;
      this.list();
    }
  }
}
</script>


